package com.candy.test;

import com.candy.bean.Blog;
import com.candy.bean.UserInfo;
import com.candy.dao.BlogMapper;
import com.candy.dao.UserInfoMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Before;
import org.junit.Test;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

public class DBDriver2 {
    BlogMapper mapper = null;
    SqlSession session = null;

    @Before
    public void before() {
        //        指定配置文件的目录
        String resource = "mybatis-config.xml";
        try {
//        读取配置文件
            InputStream inputStream = Resources.getResourceAsStream(resource);
//            通过配置文件创建SqlSessionFactory
            SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
            session = sqlSessionFactory.openSession();
            mapper = session.getMapper(BlogMapper.class);
        } catch (Exception e) {

        }
    }


    @Test
    public void test01() {
        Blog blog=mapper.selectBlogDetails(1);
        System.out.println(blog);

    }
}
